package com.slmxz.tms.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.slmxz.tms.biz.model.vo.TransitVO;
import com.slmxz.tms.common.model.Query;
import com.slmxz.tms.common.support.Condition;
import com.slmxz.tms.system.model.vo.LogVO;
import com.slmxz.tms.system.service.LogService;
import com.slmxz.tms.common.result.PageResult;
import com.slmxz.tms.common.result.Result;
import com.slmxz.tms.system.model.query.LogPageQuery;
import com.slmxz.tms.system.model.vo.LogPageVO;
import com.slmxz.tms.system.model.vo.VisitStatsVO;
import com.slmxz.tms.system.model.vo.VisitTrendVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


/**
 * 日志控制层
 * @author sunyao
 * @Date 2024-11-15
 */
@Tag(name = "08.日志接口")
@RestController
@RequestMapping("/system/log")
@RequiredArgsConstructor
public class LogController {

    private final LogService logService;


    @Operation(summary = "管理员在途订单分页")
    @GetMapping("/page")
    public PageResult<?> selectOrderPage(Query query, LogVO log) {
        IPage<LogVO> result = this.logService.selectLogPage(Condition.getPage(query),log);
        return PageResult.success(result);
    }

    @Operation(summary = "获取访问趋势")
    @GetMapping("/visitTrend")
    public Result<VisitTrendVO> getVisitTrend(
            @Parameter(description = "开始时间", example = "yyyy-MM-dd") @RequestParam String startDate,
            @Parameter(description = "结束时间", example = "yyyy-MM-dd") @RequestParam String endDate
    ) {
        LocalDate start = LocalDate.parse(startDate);
        LocalDate end = LocalDate.parse(endDate);
        VisitTrendVO data = logService.getVisitTrend(start, end);
        return Result.success(data);
    }

    @Operation(summary = "获取统计数据")
    @GetMapping("/visitStats")
    public Result<List<VisitStatsVO>> getVisitStats() {
        List<VisitStatsVO> list = logService.getVisitStats();
        return Result.success(list);
    }

}
